import { getAppInfo, getDeviceInfo } from "@/utils/common/app_util";
import { isNotEmpty } from "@/utils/common/object_util";
/**
 * 网络请求相关配置参数
 */

//超时时间 默认60s
export const TIME_OUT = 60000

//Content-Type
export const CONTENT_TYPE_JSON = 'application/json'
export const CONTENT_TYPE_FORM = 'application/x-www-form-urlencoded'

//ClientDoctor
export const CLIENT_DOCTOR = 'clientDoctor'
//ClientPsychiatrist
export const CLIENT_PSYCHIATRIST = 'clientPsychiatrist'

//接口请地址BaseUrl
export enum RequestUriType {
	//预发环境
	uat = "https://www.yiningjk.com/ynxl_api_uat/",
	//灰度环境
	gray = "https://www.yiningjk.com/gray_api/",
	//生产环境
	prod = "https://www.yiningjk.com/pro_api/",
}


//请求方法
export enum Method {
	GET = 'GET',
	POST = 'POST',
	PUT = 'PUT',
	DELETE = 'DELETE',
}

//创建请求头部
export const createHeaders = (contentType ?: string, token ?: string) => {
	const headers = {}
	headers['Content-Type'] = contentType
	if(isNotEmpty(token)) {
		headers['X-Litemall-Token'] = token
	}
	const appInfo = getAppInfo()
	headers['version'] = appInfo.versionCode
	headers['versionName'] = appInfo.versionName
	headers['deviceType'] = appInfo.deviceType
	const deviceInfo = getDeviceInfo()
	headers['deviceInfo'] = encodeURIComponent(JSON.stringify(deviceInfo))
	return headers
}

//响应结果
export interface ApiResponse<T> {
	errno ?: number,
	errmsg ?: string,
	data : T,
}

export interface RequestConfig {
	url : string;
	method : Method;
	data ?: object;
	isShowLoading : boolean;
	contentType ?: string;
}

export interface RequestFileConfig {
	url : string;
	filePath : string;
	formData ?: object;
	isShowLoading : boolean;
}
